﻿using System;
using System.Data;
using MyClever.Lib;

namespace MyClever.DefaultPlugins
{
    public class WriteXML : MissionPlugin
    {
        [Package(Direction.Input, "Defines the data, you like to write in the expected xml-files.")]
        enum Data { }

        [Package(Direction.Input, "Defines the xml file, you like to write in the data.")]
        enum XMLFiles
        {
            [Column(typeof(string), "The xml file you like to write in.")]
            XmlFilePath
        }

        [Plugin(PluginDevStatus.Production, "Writes the given data into the xml files.")]
        public WriteXML()
        {
        }

        public override void Initialize()
        {

            //This is the first Function called by the host...
            //Put anything needed to start with here first
        }

        public override void Dispose()
        {
            //Put any cleanup code in here for when the program is stopped
        }

        /// <summary>
        /// Generate new Source-content.
        /// </summary>
        protected override void Work()
        {
            DataTableReader xmlFiles = this.GetDataReader(typeof(XMLFiles));
            while (xmlFiles.Read())
            {
                this.AddNewLoggingMessage(typeof(XMLFiles), String.Format("write: {0}", xmlFiles[XMLFiles.XmlFilePath.ToString()].ToString()));

                this.GetPackageByName(typeof(Data)).WriteXml(xmlFiles[XMLFiles.XmlFilePath.ToString()].ToString());
            }
        }
    }
}
